/**
 * Copyright(c) 2006-2008, FeyaSoft Inc.
 * ====================================================================
 * Licence
 * ====================================================================
 * FeyaSoft is free software distributed under the GNU GPL version 2 or higher, 
 * GNU LGPL version 2.1 or higher as published by the Free Software Foundation. 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
 * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package("feyaSoft.util");

/**
 * This JS is used to define util functions
 *
 * @author fzhuang
 * @Date July 26, 2007
 */
feyaSoft.util.common = feyaSoft.util.common || {

    formatDateDetail : function(date) {
        if (!date) {
            return '';
        }
        var now = new Date();
        var d = now.clearTime(true);
        var notime = date.clearTime(true).getTime();
        if (notime == d.getTime()) {
            return 'Today ' + date.dateFormat('g:i a');
        }
        d = d.add('d', -6);
        if (d.getTime() <= notime) {
            return date.dateFormat('D g:i a');
        }
        return date.dateFormat('n/j g:i a');
    },

    /**
     * Transfer date hour fromat
     * @method formatDateHour
     * @param {any} obj The object being testing
     * @return date in some format
     */
    formatDateHour: function(obj){
        return obj ? obj.dateFormat('M d, Y H:i') : '';
    },

    /**
     * Transfer date fromat
     * @method formatDate
     * @param {any} obj The object being testing
     * @return date in some format
     */
    formatDate: function(obj){
        return obj ? obj.dateFormat('D, M d Y') : '';
    },

    /**
     * Transfer boolean fromat
     * @method formatBoolean
     * @param {any} obj The object being testing
     * @return yes/no
     */    
    formatBoolean: function(obj){
        return obj ? 'Yes' : 'No';  
    },
    
    /**
     * Determines whether or not the provided object is a boolean
     * @method isBoolean
     * @param {any} obj The object being testing
     * @return Boolean
     */
    isBoolean: function(obj) {
        return typeof obj == 'boolean';
    },
    
    /**
     * Determines whether or not the provided object is a function
     * @method isFunction
     * @param {any} obj The object being testing
     * @return Boolean
     */
    isFunction: function(obj) {
        return typeof obj == 'function';
    },
        
    /**
     * Determines whether or not the provided object is null
     * @method isNull
     * @param {any} obj The object being testing
     * @return Boolean
     */
    isNull: function(obj) {
        return obj === null;
    },
        
    /**
     * Determines whether or not the provided object is a legal number
     * @method isNumber
     * @param {any} obj The object being testing
     * @return Boolean
     */
    isNumber: function(obj) {
        return typeof obj == 'number' && isFinite(obj);
    },
        
    /**
     * Determines whether or not the provided object is a string
     * @method isString
     * @param {any} obj The object being testing
     * @return Boolean
     */
    isString: function(obj) {
        return typeof obj == 'string';
    },
        
    /**
     * Determines whether or not the provided object is undefined
     * @method isUndefined
     * @param {any} obj The object being testing
     * @return Boolean
     */
    isUndefined: function(obj) {
        return typeof obj == 'undefined';
    }
};